import getLastProto from './utils/getLastProto';
import extendAction from './utils/extendAction';

export default (setData, getData) => {
    return (actions) => {
        let actionInstance = getData('actionInstance');
        let modelsInstance = getData('modelInstance');

        Object.keys(actions).forEach((actionName) => {

            let Action = actions[actionName];

            extendAction(Action, {
                actions: actionInstance,
                models: modelsInstance
            });

            let action = new Action();

            action.actions = actionInstance;
            action.models = modelsInstance;

            actionInstance[actionName] = action;
        });

        setData('actionInstance', actionInstance);
    }
}